/**
 *
 */
define(['bootstrap-table',
    'bootstrap-table-zh-CN',
    'css!assets/bootstrap-table/bootstrap-table.min.css'], function () {
    var ko = {};
    ko.bootstrapTableViewModel = function (options) {
        var _height = window.screen.height;
        var _gridHeight = 500;
        var _gridSize = 10;

        if (options.autoHeight) {
            if (_height >= 900) {
                _gridHeight = 680;
                _gridSize = 15;
            }
        }
        var self = this;
        self.defaults = {
            search: false,
            strictSearch: true,
            showColumns: true,
            cache: false,
            minimumCountColumns: 2,
            clickToSelect: true,
            showToggle: false,
            singleSelect: true,
            striped: true,
            showRefresh: true,
            silent: true,
            pagination: true,
            sidePagination: 'server',
            pageNumber: 1,
            pageSize: _gridSize,
            pageList: [10, 15, 20, 50, 100],
            method: 'post',
            height: _gridHeight
        };
        self.params = $.extend({}, self.defaults, options || {});
        /**
         * 获取行选择数据
         */
        self.getSelections = function () {
            var arrRes = self.bootstrapTable("getSelections");
            return arrRes;
        };
        /**
         * 获取查询参数
         */
        self.getQueryParams = function () {

        };
        /**
         * 刷新列表
         * @param params
         */
        self.refresh = function (params) {
            if (params != null) {
                self.bootstrapTable("refresh", {
                    query: params
                });
            } else {
                self.bootstrapTable('refresh');
            }
        };
        /**
         * 列表带参数数据加载
         * @param url
         * @param params
         */
        self.load = function (url, params) {
            if (params != null) {
                self.bootstrapTable('refresh', {
                    url: url,
                    query: params
                })
            } else {
                self.bootstrapTable('refresh', {
                    url: url
                })
            }
        };
        /**
         * 获取列表属性
         */
        self.getOptions = function () {
            var tableOptions = self.bootstrapTable('getOptions');
            return tableOptions;
        };
        /**
         * 重置表格，避免表头与表格不对齐
         */
        self.resetView = function () {
            self.bootstrapTable('resetView');
        };
        /**
         *
         * @param opts
         */
        self.refreshOpts = function (opts) {
            var option = self.bootstrapTable('getOptions');
            self.bootstrapTable('refreshOptions', opts);
        };
        /**
         * 删除所有数据
         */
        self.removeAll = function () {
            self.bootstrapTable('removeAll');
        }
    };
    return ko;
});